package com.xiaoqiudong.pojo.game;

/**
 * Created with IntelliJ IDEA
 * Descroption
 * User:dell
 * Date:2025-08-16
 * Time:10:26
 */

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 标示用户的上下线状态
 */
@Component
public class OnlineUserManager {
    //表示用户在游戏大厅的用户状态
    private ConcurrentHashMap<Integer, WebSocketSession> gameHall= new ConcurrentHashMap<>();
    //表示用户在游戏房间的游戏状态
    private ConcurrentHashMap<Integer,WebSocketSession> gameRoom = new ConcurrentHashMap<>();

    public void enterGameHall(int userId,WebSocketSession webSocketSession){
        gameHall.put(userId,webSocketSession);
    }
    public void exitGameHall(int userId){
        gameHall.remove(userId);
    }
    public WebSocketSession getGameHall(int userId){
        return gameHall.get(userId);
    }
    public void enterGameRoom(int userId,WebSocketSession webSocketSession){
        gameRoom.put(userId,webSocketSession);
    }
    public void exitGameRoom(int userId){
        gameRoom.remove(userId);
    }
    public WebSocketSession getFromGameRoom(int userId){
        return gameRoom.get(userId);
    }
}
